package com.zsrt.java.day20161228.wrl.demo02;

import java.util.Arrays;

/**
 * 冒泡排序
 * 
 * {50,40,30,80,20};
 * 				                        第几轮          循环次数
 * 				  		outer  length-outer
 * 01 02 03 04			 1		4
 * 01 02 03			 	 2		3
 * 01 02				 3		2
 * 01					 4		1
 * 
 * @author Administrator
 *
 */
public class PopSort01 {
	
	public static void main(String[] args) {
		
		int[] arrays = {50,40,30,80,20};
		System.out.println(Arrays.toString(arrays));
		int length   = arrays.length;
		
		for(int outer = 0; outer < length; outer++){
//			System.out.println(outer);
			for(int inner = 1; inner < length-outer; inner++){
				
				System.out.print(inner-1+":"+inner+"\t");
				
				if(arrays[inner-1] > arrays[inner]){
					int temp      = arrays[inner-1];
					arrays[inner-1] = arrays[inner];
					arrays[inner] = temp;
				}
			}
			System.out.println();
		}
		System.out.println(Arrays.toString(arrays));
	}

}
